#ifndef _HTTPIMPL_H_
#define _HTTPIMPL_H_

#include "stdafx.h"
#include <io/iframe.h>
#include <net/idns.h>
#include <dlcom/autolock.h>
#include <utilex/thread.hpp>
#include <compat/thread.h>

#include "dns_parser.h"

class CDnsImpl :	public	IDns,
					public	IPlugin,
					public	IPluginRun,
					public	CDnsParser,
					public  ithread,
					public	CUnknownImp
{
public:
	CDnsImpl();
	virtual ~CDnsImpl(void);
public:
	UNKNOWN_IMP3_(IPlugin, IPluginRun, IDns);
	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	std_method_impl init_class(IBase* prot, IBase* punkOuter);
	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	std_method(Init)(void*);
	std_method(Uninit)();
	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	std_method(Start)();
	std_method(Stop)();
	//////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////
	//IDns
	std_method(GetURLtoHost)(	const char* url, const char* lastip,
								const char* name, IDnsProc* proc,
								int* cache, char* ip, int nocache);
	std_method(DnsSyncResultIP)(const char* url, IDnsProc* proc);
	//////////////////////////////////////////////////////////////////////////
public:
	void	dns_func(void *pData, const char* name, const char* url, const char* ip, void* cb);
	void	dns_endfunc(void *pData, const char* name, const char* url, const char* ip, void* cb);
	void	dns_errorfunc(void *pData, const char* name, const char* url, const char* ip, void* cb);
	void	dns_signal(int istart);
	void	dnspro(int error, const char* url, const char* ip, void* cb);

protected:
	void	run();
	void	threadstop();
private:
	void	setiptable(const char* url,const char* ip);
	int		getiptable(const char* url, const char* lastip,char* ip);

private:
	_lComPtr<IComRunningObjectTable>	m_pRot;
	_lComPtr<IAsynIo>					m_pIAsynIo;
	_lComPtr<IAsynFrame>				m_pIAsynFrame;

	typedef list<string>				iplist;
	map<string, iplist>					m_mapURLtoIPtable;
	CAutoCriticalSection				m_Lock;

	os_sem_t sem;
};


#endif